package main

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"time"
)

var ctx = context.Background()

func main() {
	rdb := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
		DB:       0,
	})
	var err error
	var val string
	err = rdb.Set(ctx, "key1", "value1", 0).Err()
	if err != nil {
		panic(err)
	}
	val, err = rdb.Get(ctx, "key1").Result()
	if err != nil {
		panic(err)
	}
	fmt.Println(val)
	var set bool
	set, err = rdb.SetNX(ctx, "k2", "v2", 10*time.Second).Result()
	if err != nil {
		panic(err)
	}
	set, err = rdb.SetNX(ctx, "k3", "v3", redis.KeepTTL).Result()
	set, err = rdb.SetNX(ctx, "k3", "v33", redis.KeepTTL).Result()
	if err != nil {
		panic(err)
	}
	fmt.Println(set)
}
